package com.example.studentsRoom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.studentsRoom.entity.SystemAdmin;
import com.example.studentsRoom.form.RuleForm;
import com.example.studentsRoom.mapper.SystemAdminMapper;
import com.example.studentsRoom.service.ISystemAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.studentsRoom.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2022-07-19
 */
@Service
public class SystemAdminService extends ServiceImpl<SystemAdminMapper, SystemAdmin> implements ISystemAdminService {

    @Autowired
    SystemAdminMapper systemAdminMapper;

    @Override
    public ResultVo login(RuleForm ruleForm) {
        //1.检查账号是否正确
        QueryWrapper<SystemAdmin> wrapper=new QueryWrapper<>();
        wrapper.eq("s_account",ruleForm.getAccount());
        SystemAdmin admin = systemAdminMapper.selectOne(wrapper);

        ResultVo resultVo=new ResultVo();
        if(admin==null){
            resultVo.setData(-1);
        }else{
            //2.判断密码是否正确
            wrapper.eq("s_pwd",ruleForm.getPassword());
            SystemAdmin systemAdmin = systemAdminMapper.selectOne(wrapper);
            if (systemAdmin==null){
                resultVo.setCode(-2);
            }else{
                resultVo.setCode(0);
                resultVo.setData(admin);
            }
        }

        return resultVo;
    }
}
